package x2rel.qMap.core;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import x2rel.qMap.logger.Logging;

public class Core{// implements Runnable {

    private File algXqFile;
    private File equivFile;
    private AlgebraXqHandler algxq;
    private AlgebraRelHandler rel;
    private EquivalenciaHandler eq;
    private ArrayList<Variables> vars;
    private ArrayList<Equivalencias> equivs;
    private String saida;

    public Core(File xAlgFile, File equivFile) {
        this.algXqFile = xAlgFile;
        this.equivFile = equivFile;
    }

    //@Override
    public void run() {
        /* Instancia o objeto que manipula o arquivo de algebra xquery */
        algxq = new AlgebraXqHandler(algXqFile);
        
        /* Traz os valores  */
        vars = algxq.getFinalVars();
        
        /* Instancia o objeto que manupula a xml da equivalencia */ 
        eq = new EquivalenciaHandler(equivFile, vars);
        
        // carrega o array com as equivalencias
        equivs = eq.executa();
        
        for (Equivalencias v : equivs) {
            Logging.getInstance().log("Equivalencia!\n" + Utils.dump(v));
        }
        /* Gera álgebra relacional */
        rel = new AlgebraRelHandler(equivs, vars);
        
        saida = rel.generateAlgRel();
        
        //return saida;
        
    }

    public String getOutput() {
        return saida;
    }
    
    
}
